<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x6570;&amp;#x7EC4;&amp;#x662F;&amp;#x8868;&amp;#x793A;&amp;#x96C6;&amp;#x5408;&amp;#x7684;&amp;#x503C;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x503C;&amp;#x662F;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;">
<meta property="og:type" content="article">
<meta property="og:title" content="js 的数组">
<meta property="og:url" content="https://hongqinma.github.io/2014/05/11/js-的数组/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x6570;&amp;#x7EC4;&amp;#x662F;&amp;#x8868;&amp;#x793A;&amp;#x96C6;&amp;#x5408;&amp;#x7684;&amp;#x503C;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x503C;&amp;#x662F;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;">
<meta property="og:updated_time" content="2016-11-07T15:01:29.543Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js 的数组">
<meta name="twitter:description" content="&amp;#x6570;&amp;#x7EC4;&amp;#x662F;&amp;#x8868;&amp;#x793A;&amp;#x96C6;&amp;#x5408;&amp;#x7684;&amp;#x503C;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x503C;&amp;#x662F;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;&amp;#xFF0C;&amp;#x6BCF;&amp;#x4E00;&amp;#x4E2A;&amp;#x5143;&amp;#x7D20;">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2014/05/11/js-的数组/"/>


  <title> js 的数组 | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                js 的数组
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2014-05-11T20:52:03+08:00" content="2014-05-11">
              2014-05-11
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2014/05/11/js-的数组/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2014/05/11/js-的数组/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2014/05/11/js-的数组/" class="leancloud_visitors" data-flag-title="js 的数组">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">visitors </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
          <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#x6570;&#x7EC4;&#x662F;&#x8868;&#x793A;&#x96C6;&#x5408;&#x7684;&#x503C;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x503C;&#x662F;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x6709;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x4EE5;&#x6570;&#x5B57;&#x8868;&#x793A;&#xFF0C;&#x53EB;&#x7D22;&#x5F15;&#x3002;<br>&#x6570;&#x7EC4;&#x7EE7;&#x627F;&#x81EA; Array.prototype.</p>
<h2 id="js-&#x7684;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;-&#x6570;&#x7EC4;Array"><a href="#js-&#x7684;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;-&#x6570;&#x7EC4;Array" class="headerlink" title="js &#x7684;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;: &#x6570;&#x7EC4;Array"></a>js &#x7684;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;: &#x6570;&#x7EC4;Array</h2><h2 id="&#x6570;&#x7EC4;&#x58F0;&#x660E;"><a href="#&#x6570;&#x7EC4;&#x58F0;&#x660E;" class="headerlink" title="&#x6570;&#x7EC4;&#x58F0;&#x660E;"></a>&#x6570;&#x7EC4;&#x58F0;&#x660E;</h2><ul>
<li>&#x76F4;&#x63A5;&#x91CF;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;&#x6570;&#x7EC4;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> empty = []; <span class="comment">// &#x6CA1;&#x6709;&#x5143;&#x7D20;&#x7684;&#x7A7A;&#x6570;&#x7EC4;</span></div><div class="line"><span class="keyword">var</span> num = [<span class="number">1</span>,<span class="number">3</span>,<span class="number">2</span>,<span class="number">4</span>,<span class="number">5</span>]; <span class="comment">// &#x6709;5&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x6570;&#x7EC4;</span></div><div class="line"><span class="keyword">var</span> misc = [<span class="number">1</span>, <span class="literal">true</span>, <span class="string">&quot;a&quot;</span>, ]; <span class="comment">// &#x6709;&#x4E0D;&#x540C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5143;&#x7D20;&#x7684;&#x6570;&#x7EC4;</span></div><div class="line"><span class="keyword">var</span> misc2 = [[<span class="number">1</span>], {<span class="attr">x</span>: <span class="number">1</span>, <span class="attr">y</span>: <span class="number">2</span>},[<span class="number">2</span>, {<span class="attr">x</span>:<span class="number">2</span>, <span class="attr">y</span>: <span class="number">1</span>}]];</div></pre></td></tr></table></figure>
<p>&#x6570;&#x7EC4;&#x76F4;&#x63A5;&#x91CF;&#x4E2D;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<ul>
<li>&#x4F7F;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>();<span class="comment">// &#x6570;&#x7EC4;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570; &#x521B;&#x5EFA;&#x7684;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x6570;&#x7EC4;</span></div><div class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="string">&quot;4&quot;</span>);<span class="comment">// &#x53EA;&#x6709;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x6570;&#x503C;&#x7684;&#x65F6;&#x5019; &#x624D;&#x8868;&#x793A;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;</span></div><div class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">5</span>, <span class="number">4</span>, <span class="string">&quot;abc&quot;</span>); <span class="comment">// &#x663E;&#x793A;&#x7684;&#x6307;&#x5B9A;&#x4E24;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x6216;&#x8005;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x4E2A;&#x975E;&#x6570;&#x503C;&#x5143;&#x7D20;</span></div></pre></td></tr></table></figure>
<h2 id="&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x8BFB;&#x548C;&#x5199;"><a href="#&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x8BFB;&#x548C;&#x5199;" class="headerlink" title="&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x8BFB;&#x548C;&#x5199;"></a>&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x8BFB;&#x548C;&#x5199;</h2><h3 id="&#x6570;&#x7EC4;&#x7684;&#x5408;&#x6CD5;&#x8868;&#x8FBE;&#x5F0F;"><a href="#&#x6570;&#x7EC4;&#x7684;&#x5408;&#x6CD5;&#x8868;&#x8FBE;&#x5F0F;" class="headerlink" title="&#x6570;&#x7EC4;&#x7684;&#x5408;&#x6CD5;&#x8868;&#x8FBE;&#x5F0F;"></a>&#x6570;&#x7EC4;&#x7684;&#x5408;&#x6CD5;&#x8868;&#x8FBE;&#x5F0F;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = [<span class="string">&quot;world&quot;</span>]; </div><div class="line"><span class="keyword">var</span> value = a[<span class="number">0</span>]; <span class="comment">// &#x8BFB;&#x53D6;&#x7B2C; 0 &#x4E2A;&#x5143;&#x7D20;</span></div><div class="line">a[<span class="number">1</span>] = <span class="number">10</span>; <span class="comment">// &#x8BBE;&#x7F6E;&#x503C;</span></div><div class="line"><span class="keyword">var</span> b = [];</div><div class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; <span class="number">5</span>; i++){</div><div class="line">  a[length++] = i;  <span class="comment">// &#x5C06; 0 - 4 &#x7684;&#x6570;&#x503C;&#x88C5;&#x5230;&#x6570;&#x7EC4;&#x4E2D;</span></div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">var</span> j = <span class="number">2</span>;</div><div class="line">a[j] = <span class="number">3</span>;  <span class="comment">// &#x5199;&#x7B2C;&#x4E8C;&#x4E2A;&#x5143;&#x7D20;</span></div><div class="line">a[j+<span class="number">1</span>] = <span class="string">&quot;abc&quot;</span>; <span class="comment">// &#x5199;&#x7B2C;&#x4E09;&#x4E2A;&#x5143;&#x7D20;</span></div><div class="line">a[a[j]] = a[<span class="number">0</span>];  <span class="comment">// &#x8BFB;&#x7B2C; 0 &#x4E2A;&#x5143;&#x7D20;&#x548C;&#x7B2C; 2 &#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x5199;&#x7B2C; 3 &#x4E2A;&#x5143;&#x7D20;</span></div></pre></td></tr></table></figure>
<h3 id="&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x548C;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;"><a href="#&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x548C;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;" class="headerlink" title="&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x548C;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;"></a>&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x548C;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;</h3><p>&#x6570;&#x7EC4;&#x662F;&#x5BF9;&#x8C61;&#x7684;&#x7279;&#x6B8A;&#x5F62;&#x5F0F;&#x3002;<br>&#x5E38;&#x89C4;&#x7684;&#x5BF9;&#x8C61;&#x5982;&#xFF1A;<code>o = {}; o[1] = &quot;one&quot;; // &#x53EF;&#x4EE5;&#x7528;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x6765;&#x8BBF;&#x95EE;</code>&#x3002;<br>&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x53EA;&#x80FD;&#x662F; 0 ~ 2&#x7684;32&#x6B21;&#x5E42; - 2 &#x4E4B;&#x95F4;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x7D22;&#x5F15;&#x662F;&#x5C5E;&#x6027;&#x540D;&#x3002;<br>&#x8D1F;&#x6570;&#x548C;&#x6D6E;&#x70B9;&#x6570;&#x4E5F;&#x53EF;&#x4EE5;&#x6765;&#x7D22;&#x5F15;&#x6570;&#x7EC4;&#x3002;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x8F6C;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#x5F53;&#x6210;&#x5E38;&#x89C4;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#xFF0C;<br>&#x800C;&#x975E;&#x8D1F;&#x6574;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x88AB;&#x4F7F;&#x7528;&#x4E86;&#xFF1A; <code>arr[&quot;99&quot;]</code>, &#x5F53;&#x505A;&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x800C;&#x975E;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;<br>&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x662F;&#x5C5E;&#x6027;&#x7684;&#x7279;&#x6B8A;&#x7C7B;&#x578B;&#xFF0C;&#x56E0;&#x6B64;&#x6570;&#x7EC4;&#x7684;&#x7D22;&#x5F15;&#x627E;&#x4E0D;&#x5230;&#x503C;&#x65F6;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x800C;&#x662F; undefined&#x3002;</p>
<h2 id="&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;"><a href="#&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;" class="headerlink" title="&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;"></a>&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;</h2><p>&#x6BCF;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x90FD;&#x6709;&#x4E00;&#x4E2A; length &#x5C5E;&#x6027;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>();</div><div class="line"><span class="built_in">console</span>.log(arr.lengh); <span class="comment">//&#x83B7;&#x53D6;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;</span></div><div class="line"><span class="comment">// length&#x5C5E;&#x6027;&#x662F;&#x52A8;&#x6001;&#x6539;&#x53D8;&#x7684; &#x901A;&#x8FC7;arr.length&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x8FFD;&#x52A0;</span></div></pre></td></tr></table></figure>
<p>&#x53EF;&#x4EE5;&#x5C06;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#x8BBE;&#x7F6E;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</div><div class="line">arr.length = [<span class="number">1</span>]; <span class="comment">// arr &#x73B0;&#x5728;&#x4E3A; [1];</span></div><div class="line">arr.length = []; <span class="comment">// &#x5220;&#x9664; arr &#x4E2D;&#x7684;&#x5143;&#x7D20;</span></div><div class="line">arr.length = <span class="number">5</span>; <span class="comment">// &#x957F;&#x5EA6;&#x4E3A; 4&#xFF0C;&#x4F46;&#x6CA1;&#x6709;&#x5143;&#x7D20;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E; new Array(5);</span></div></pre></td></tr></table></figure>
<p>ECMAScript 5&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Object.defineProperty() &#x6765;&#x8BBE;&#x7F6E;&#x6570;&#x7EC4;&#x7684; length &#x4E3A;&#x53EA;&#x8BFB;&#x7684;&#x3002;</p>
<h2 id="&#x7A00;&#x758F;&#x6570;&#x7EC4;"><a href="#&#x7A00;&#x758F;&#x6570;&#x7EC4;" class="headerlink" title="&#x7A00;&#x758F;&#x6570;&#x7EC4;"></a>&#x7A00;&#x758F;&#x6570;&#x7EC4;</h2><p>&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x662F;&#x5305;&#x542B;&#x4ECE; 0 &#x5F00;&#x59CB;&#x7684;&#x4E0D;&#x8FDE;&#x7EED;&#x7D22;&#x5F15;&#x7684;&#x6570;&#x7EC4;&#x3002;<br>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Array() &#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;&#x7B80;&#x5355;&#x6307;&#x5B9A;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x5927;&#x4E8E;&#x5F53;&#x524D;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#x6765;&#x5B9A;&#x4E49;&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x3002;<br>&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; delete &#x64CD;&#x4F5C;&#x7B26;&#x6765;&#x521B;&#x5EFA;&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">5</span>);</div><div class="line"><span class="keyword">var</span> arr[<span class="number">99</span>] = <span class="number">1</span>; <span class="comment">// &#x8D4B;&#x503C;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5143;&#x7D20;1&#xFF0C;length &#x53D8;&#x4E3A; 100</span></div><div class="line"><span class="keyword">var</span> a2 = [];</div><div class="line"><span class="keyword">var</span> a3 = [,]; <span class="comment">// &#x6B64;&#x65F6;&#x6570;&#x7EC4;&#x6CA1;&#x6709;&#x5143;&#x7D20;&#xFF0C;&#x957F;&#x5EA6;&#x662F; 1&#xFF1B;&#x4E5F;&#x662F;&#x7A00;&#x758F;&#x6570;&#x7EC4;</span></div></pre></td></tr></table></figure>
<p>&#x6CE8;&#xFF1A;&#x5F53;&#x7ED9;&#x76F4;&#x63A5;&#x91CF;&#x4E2D;&#x7701;&#x7565;&#x503C;&#x65F6;&#x4E0D;&#x4F1A;&#x521B;&#x5EFA;&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x3002;&#x56E0;&#x4E3A;&#x7701;&#x7565;&#x7684;&#x503C;&#x662F; undefined &#x7C7B;&#x578B;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a5 = [,,,]; <span class="comment">// &#x4E0D;&#x662F;&#x7A00;&#x758F;&#x6570;&#x7EC4;</span></div><div class="line"><span class="keyword">var</span> a4 = [<span class="literal">undefined</span>]; <span class="comment">// &#x6B64;&#x65F6;&#x6570;&#x7EC4;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x6570;&#x503C; undefined &#x7C7B;&#x578B;&#x3002;</span></div></pre></td></tr></table></figure>
<h2 id="&#x6570;&#x7EC4;&#x5192;&#x6CE1;&#x6392;&#x5E8F;"><a href="#&#x6570;&#x7EC4;&#x5192;&#x6CE1;&#x6392;&#x5E8F;" class="headerlink" title="&#x6570;&#x7EC4;&#x5192;&#x6CE1;&#x6392;&#x5E8F;"></a>&#x6570;&#x7EC4;&#x5192;&#x6CE1;&#x6392;&#x5E8F;</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr17 = [<span class="number">56</span>,<span class="number">45</span>,<span class="number">23</span>,<span class="number">78</span>,<span class="number">67</span>,<span class="number">34</span>,<span class="number">96</span>,<span class="number">39</span>,<span class="number">44</span>,<span class="number">23</span>,<span class="number">45</span>,<span class="number">37</span>,<span class="number">85</span>];</div><div class="line"><span class="keyword">var</span> outer = <span class="number">0</span>;</div><div class="line"><span class="keyword">var</span> inner = <span class="number">0</span>;</div><div class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; arr17.length - <span class="number">1</span>; i++){</div><div class="line">    <span class="keyword">var</span> flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">for</span>(<span class="keyword">var</span> j = <span class="number">0</span> ; j &lt; arr17.length - <span class="number">1</span> - i; j++){</div><div class="line">        <span class="keyword">if</span>(arr17[j] &gt; arr17[j+<span class="number">1</span>]){</div><div class="line">            <span class="keyword">var</span> tempValue = arr17[j+<span class="number">1</span>];</div><div class="line">            arr17[j+<span class="number">1</span>] = arr17[j];</div><div class="line">            arr17[j] = tempValue;</div><div class="line">            flag = <span class="literal">false</span>;</div><div class="line">        }</div><div class="line">        inner++;</div><div class="line">    }</div><div class="line">    outer++;</div><div class="line">    <span class="keyword">if</span>(flag){</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">    }</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;"><a href="#&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;" class="headerlink" title="&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;"></a>&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;</h2><ul>
<li>push();<ul>
<li>&#x5C3E;&#x90E8;&#x8FFD;&#x52A0;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;push &#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E0E;&#x7ED9;&#x6570;&#x7EC4; a[a.length] &#x8D4B;&#x503C;&#x4E00;&#x6837;&#xFF1B;</li>
<li>&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;&#x957F;&#x5EA6;</li>
<li>&#x64CD;&#x4F5C;&#x539F;&#x6570;&#x7EC4;&#xFF0C;&#x672B;&#x5C3E;&#x8FFD;&#x52A0;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = [];</div><div class="line">a.push(<span class="string">&quot;ab&quot;</span>);</div><div class="line">a.push(<span class="string">&quot;bc&quot;</span>,<span class="string">&quot;cd&quot;</span>);  <span class="comment">// a = [&quot;ab&quot;,&quot;bc&quot;,&quot;cd&quot;];</span></div><div class="line">a.push(<span class="string">&quot;123&quot;</span>,[<span class="string">&quot;e&quot;</span>,<span class="string">&quot;f&quot;</span>]);  <span class="comment">// a = [&quot;ab&quot;,&quot;bc&quot;,&quot;cd&quot;,&quot;123&quot;,[&quot;e&quot;,&quot;f&quot;]];</span></div></pre></td></tr></table></figure>
<ul>
<li>pop();<ul>
<li>&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x88AB;&#x5220;&#x9664;&#x7684;&#x8FD9;&#x4E2A;&#x5143;&#x7D20;</li>
<li>&#x64CD;&#x4F5C;&#x539F;&#x6570;&#x7EC4;</li>
</ul>
</li>
<li>shift();<ul>
<li>&#x5220;&#x9664;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x88AB;&#x5220;&#x9664;&#x7684;&#x5143;&#x7D20;</li>
</ul>
</li>
<li>unshift();<ul>
<li>&#x5411;&#x6570;&#x7EC4;&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E4B;&#x524D;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x6216;&#x591A;&#x4E2A;&#x65B0;&#x7684;&#x5143;&#x7D20;</li>
<li>&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x65B0;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;</li>
</ul>
</li>
<li>concat(); Array.concat() &#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x5E76;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;<ul>
<li>&#x65B0;&#x7684;&#x6570;&#x7EC4;&#x548C;&#x65E7;&#x7684;&#x6570;&#x7EC4;&#x62FC;&#x63A5;&#xFF0C;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6570;&#x7EC4;</li>
<li>&#x4E0D;&#x4FEE;&#x6539;&#x539F;&#x6570;&#x7EC4;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>];</div><div class="line">arr.concat([<span class="number">3</span>,<span class="number">4</span>]);  <span class="comment">// &#x8FD4;&#x56DE; [1,2,3,4]</span></div><div class="line">arr.concat(<span class="number">3</span>,[<span class="number">4</span>,[<span class="number">5</span>,<span class="number">6</span>]]); <span class="comment">// &#x8FD4;&#x56DE; [1,2,3,4,[5,6]]</span></div></pre></td></tr></table></figure>
<ul>
<li>slice(); Array.slice()&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x6307;&#x5B9A;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x4E2A;&#x7247;&#x6BB5;&#x6216;&#x5B50;&#x6570;&#x7EC4;<ul>
<li>&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A; &#x5F00;&#x59CB;&#x7D22;&#x5F15;&#xFF0C;&#x7ED3;&#x675F;&#x7D22;&#x5F15;&#xFF0C;&#x8FD4;&#x56DE;&#x5305;&#x542B;&#x5F00;&#x59CB;&#x7D22;&#x5F15;&#xFF0C;&#x4E0D;&#x5305;&#x542B;&#x7ED3;&#x675F;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;&#x4E4B;&#x95F4;&#x7684;&#x6240;&#x6709;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#xFF1B;</li>
<li>&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x5305;&#x542B;&#x5F00;&#x59CB;&#x4F4D;&#x7F6E;&#x5230;&#x6570;&#x7EC4;&#x7ED3;&#x5C3E;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;</li>
<li>&#x53C2;&#x6570;&#x662F;&#x8D1F;&#x6570;&#xFF0C;&#x76F8;&#x5BF9;&#x4E8E;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#x7684;&#x3002;&#x5982;&#x53C2;&#x6570; -1 &#x6307;&#x5B9A;&#x4E86;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;-2 &#x662F;&#x5012;&#x6570;&#x7B2C;&#x4E8C;&#x4E2A;</li>
<li>&#x4ECE;&#x539F;&#x6765;&#x7684;&#x6570;&#x7EC4;&#x4E2D;&#x622A;&#x53D6;&#x51FA;&#x6765;&#x6307;&#x5B9A;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x5143;&#x7D20;&#xFF0C;&#x4EA7;&#x751F;&#x65B0;&#x7684;&#x6570;&#x7EC4;</li>
<li>&#x4E0D;&#x64CD;&#x4F5C;&#x539F;&#x6570;&#x7EC4;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = [<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</div><div class="line">a.slice (<span class="number">0</span>,<span class="number">3</span>); <span class="comment">// [0,1,2];</span></div><div class="line">a.slice(<span class="number">3</span>); <span class="comment">// [3,4,5]</span></div><div class="line">a.slice(<span class="number">1</span>,<span class="number">-1</span>); <span class="comment">// [1,2,3,4];</span></div><div class="line">a.slice(<span class="number">-3</span>,<span class="number">-2</span>); <span class="comment">// [3]</span></div></pre></td></tr></table></figure>
<ul>
<li>splice(); Array.splice()&#x662F;&#x6570;&#x7EC4;&#x4E2D;&#x63D2;&#x5165;&#x6216;&#x5220;&#x9664;&#x5143;&#x7D20;&#x7684;&#x65B9;&#x6CD5;&#x3002;<ul>
<li>&#x4F1A;&#x4FEE;&#x6539;&#x8C03;&#x7528;&#x6570;&#x7EC4;&#xFF0C;</li>
<li>&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x5F00;&#x59CB;&#x7684;&#x4E0B;&#x6807;,&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x6307;&#x5B9A;&#x4E86;&#x5220;&#x9664;&#x539F;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;&#xFF1B;</li>
<li>&#x5982;&#x679C;&#x7701;&#x7565;&#x4E86;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x4ECE;&#x5F00;&#x59CB;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;&#x540E;&#x7684;&#x5143;&#x7D20;&#x90FD;&#x88AB;&#x5220;&#x9664;&#xFF1B;</li>
<li>&#x53EF;&#x4EE5;&#x6709;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x56DB;&#x4E2A;&#x53C2;&#x6570;&#x2026;&#x8DDF;&#x5728;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x540E;&#x7684;&#x4EFB;&#x610F;&#x591A;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x9700;&#x8981;&#x63D2;&#x5165;&#x539F;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x4ECE;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x7684;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;&#x63D2;&#x5165;&#xFF1B;</li>
<li>&#x8BE5;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x5220;&#x9664;&#x5143;&#x7D20;&#x7EC4;&#x6210;&#x7684;&#x6570;&#x7EC4;,&#x5982;&#x679C;&#x6CA1;&#x6709;&#x66FF;&#x6362;&#x5219;&#x8FD4;&#x56DE;&#x7A7A;&#x6570;&#x7EC4;&#x3002;</li>
</ul>
</li>
<li>join(); &#x5C06;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#x90FD;&#x8F6C;&#x5316;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#x5E76;&#x8FDE;&#x63A5;&#x5230;&#x4E00;&#x8D77;<ul>
<li>&#x8FD4;&#x56DE;&#x6700;&#x7EC8;&#x751F;&#x6210;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
<li>&#x662F; String.split() &#x65B9;&#x6CD5;&#x7684;&#x9006;&#x5411;&#x64CD;&#x4F5C;&#x3002;String.split() &#x662F;&#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x5206;&#x9694;&#x6210;&#x5206;&#x9694;&#xFF0C;&#x8FD4;&#x56DE;&#x6570;&#x7EC4;&#xFF1B;</li>
</ul>
</li>
<li>reverse(); <ul>
<li>&#x53CD;&#x8F6C;&#x6570;&#x7EC4;</li>
<li>&#x64CD;&#x4F5C;&#x539F;&#x6570;&#x7EC4;</li>
<li>&#x8FD4;&#x56DE;&#x64CD;&#x4F5C;&#x540E;&#x7684;&#x9006;&#x5411;&#x6570;&#x7EC4;</li>
</ul>
</li>
<li>sort(); Array.sort() &#x65B9;&#x6CD5;&#x5C06;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x6392;&#x5E8F;&#x5E76;&#x8FD4;&#x56DE;&#x6392;&#x5E8F;&#x540E;&#x7684;&#x6570;&#x7EC4;<ul>
<li>&#x64CD;&#x4F5C;&#x539F;&#x6570;&#x7EC4;&#xFF1B;</li>
<li>&#x8FD4;&#x56DE;&#x6392;&#x5E8F;&#x540E;&#x7684;&#x6570;&#x7EC4;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">sort</span>(<span class="params">arr, fn</span>) </span>{</div><div class="line">      <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; arr.length - <span class="number">1</span>; i++) {</div><div class="line">          <span class="keyword">var</span> flag = <span class="literal">true</span>;</div><div class="line">          <span class="keyword">for</span> (<span class="keyword">var</span> j = <span class="number">0</span>; j &lt; arr.length - <span class="number">1</span> - i; j++) {</div><div class="line">              <span class="keyword">if</span> (fn(arr[j], arr[j + <span class="number">1</span>]) &gt; <span class="number">0</span>) {</div><div class="line">                  <span class="keyword">var</span> temp = arr[j];</div><div class="line">                  arr[j] = arr[j + <span class="number">1</span>];</div><div class="line">                  arr[j + <span class="number">1</span>] = temp;</div><div class="line">                  flag = <span class="literal">false</span>;</div><div class="line">              }</div><div class="line">          }</div><div class="line">          <span class="keyword">if</span> (flag) {</div><div class="line">              <span class="keyword">break</span>;</div><div class="line">          }</div><div class="line">      }</div><div class="line">      <span class="keyword">return</span> arr;</div><div class="line">  }</div></pre></td></tr></table></figure>
<ul>
<li>toString()<ul>
<li>&#x548C;&#x4E0D;&#x4F7F;&#x7528;&#x4EFB;&#x4F55;&#x53C2;&#x6570;&#x8C03;&#x7528; join() &#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[<span class="number">1</span>,<span class="number">2</span>].toString();  <span class="comment">// &quot;1,2&quot;</span></div><div class="line">[<span class="number">1</span>,<span class="number">2</span>,[<span class="number">3</span>,<span class="string">&quot;c&quot;</span>,<span class="number">5</span>]].toString(); <span class="comment">// &quot;1,2,3,c,5&quot;</span></div></pre></td></tr></table></figure>
<ul>
<li>toLocalString() &#x65B9;&#x6CD5;&#x662F; toString() &#x65B9;&#x6CD5;&#x7684;&#x672C;&#x5730;&#x5316;&#x7248;&#x672C;&#xFF0C;&#x4F7F;&#x7528;&#x672C;&#x5730;&#x5316;&#x5206;&#x9694;&#x7B26;&#x5C06;&#x8FD9;&#x4E9B;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#x751F;&#x6210;&#x6700;&#x7EC8;&#x5B57;&#x7B26;&#x4E32;&#x3002;</li>
</ul>
<h2 id="ECMAScript-5-&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;"><a href="#ECMAScript-5-&#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;" class="headerlink" title="ECMAScript 5 &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;"></a>ECMAScript 5 &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;</h2><p>ECMAScript 5 &#x5B9A;&#x4E49;&#x4E86; 9 &#x4E2A;&#x65B0;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x6765;&#x904D;&#x5386;&#x3001;&#x6620;&#x5C04;&#x3001;&#x8FC7;&#x6EE4;&#x3001;&#x68C0;&#x6D4B;&#x3001;&#x7B80;&#x5316;&#x548C;&#x641C;&#x7D22;&#x6570;&#x7EC4;&#xFF1B;<br>&#x5927;&#x591A;&#x6570; ECMAScript 5 &#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;<br>&#x5982;&#x679C;&#x6709;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5219;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x88AB;&#x770B;&#x505A;&#x662F;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x65B9;&#x6CD5;&#x3002;<br>&#x5373;&#x5728;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x65F6;&#x4F20;&#x9012;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4F5C;&#x4E3A;&#x5B83;&#x7684; this &#x5173;&#x952E;&#x5B57;&#x7684;&#x503C;&#x6765;&#x4F7F;&#x7528;&#x3002;<br><strong>ECMAScript 5 &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x65B9;&#x6CD5;&#x90FD;&#x4E0D;&#x4F1A;&#x4FEE;&#x6539;&#x539F;&#x59CB;&#x6570;&#x7EC4;&#x3002;</strong></p>
<ul>
<li>indexOf()&#x548C;lastIndexOf(); &#x641C;&#x7D22;&#x6574;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;&#x5177;&#x6709;&#x7ED9;&#x5B9A;&#x503C;&#x7684;&#x5143;&#x7D20;<ul>
<li>&#x67E5;&#x627E;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;</li>
<li>&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x8981;&#x67E5;&#x627E;&#x7684;&#x5143;&#x7D20;,</li>
<li>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x5F00;&#x59CB;&#x67E5;&#x627E;&#x7684;&#x4E0B;&#x6807;,</li>
<li>&#x627E;&#x5230;&#x5219;&#x8FD4;&#x56DE;&#x627E;&#x5230;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x627E;&#x4E0D;&#x5230;&#x5219;&#x8FD4;&#x56DE;-1</li>
</ul>
</li>
<li>lastIndexOf();<ul>
<li>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E5F;&#x662F;&#x67E5;&#x627E;&#x5143;&#x7D20;,&#x4ECE;&#x540E;&#x9762;&#x5411;&#x524D;&#x9762;&#x627E;,&#x627E;&#x5230;&#x5219;&#x8FD4;&#x56DE;&#x5BF9;&#x5E94;&#x7684;&#x4E0B;&#x6807;,&#x627E;&#x4E0D;&#x5230;&#x5219;&#x8FD4;&#x56DE;-1&#xFF1B;</li>
<li>&#x7B2C;&#x4E8C;&#x4E2A;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x662F;&#x8D1F;&#x6570;&#xFF0C;&#x4EE3;&#x8868;&#x76F8;&#x5BF9;&#x6570;&#x7EC4;&#x672B;&#x5C3E;&#x7684;&#x504F;&#x79FB;&#x91CF;&#xFF1B;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">findall</span>(<span class="params">a, x</span>)</span>{</div><div class="line">  <span class="keyword">var</span> results = [],</div><div class="line">      len = a.length,</div><div class="line">      index = <span class="number">0</span>;</div><div class="line">  <span class="keyword">while</span>(index &lt; len){</div><div class="line">    index = a.indexOf(x, index);</div><div class="line">    <span class="keyword">if</span> (pos === <span class="number">-1</span>) <span class="keyword">break</span>;  <span class="comment">// &#x672A;&#x627E;&#x5230;&#xFF0C;&#x5B8C;&#x6210;&#x641C;&#x7D22;</span></div><div class="line">    results.push(index); <span class="comment">// &#x5426;&#x5219;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x5B58;&#x50A8;&#x7D22;&#x5F15;</span></div><div class="line">    index = index + <span class="number">1</span>;</div><div class="line">  }</div><div class="line">  returen results;  <span class="comment">// &#x8FD4;&#x56DE;&#x5305;&#x542B;&#x7D22;&#x5F15;&#x7684;&#x6570;&#x7EC4;</span></div><div class="line">}</div></pre></td></tr></table></figure>
<ul>
<li>every() &#x548C; some(); &#x6570;&#x7EC4;&#x7684;&#x903B;&#x8F91;&#x5224;&#x5B9A;&#xFF0C;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x51FD;&#x6570;,&#x5224;&#x65AD;&#x6BCF;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x662F;&#x5426;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF1B;<ul>
<li>every() &#x65B9;&#x6CD5;&#x9488;&#x5BF9;&#x6240;&#x6709;&#x7684;&#x5143;&#x7D20;&#x5224;&#x65AD;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x5168;&#x4E3A; true&#xFF0C;&#x5219;&#x8FD4;&#x56DE;true&#xFF1B;</li>
<li>every() &#x65B9;&#x6CD5;&#x6709;&#x4E00;&#x4E2A;&#x4E0D;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x7684;&#x5219;&#x8FD4;&#x56DE; false</li>
<li>some() &#x65B9;&#x6CD5;&#x6240;&#x6709;&#x7684;&#x5143;&#x7D20;&#x5224;&#x65AD;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x6709;&#x4E00;&#x4E2A;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x7684;&#x5219;&#x8FD4;&#x56DE; true</li>
<li>some() &#x65B9;&#x6CD5;&#x5168;&#x4E3A; false, &#x5219;&#x8FD4;&#x56DE; false</li>
</ul>
</li>
<li>map() &#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x8C03;&#x7528;&#x7684;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x4F20;&#x9012;&#x7ED9;&#x6307;&#x5B9A;&#x7684;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5305;&#x542B;&#x8BE5;&#x51FD;&#x6570;&#x7684;&#x6570;&#x7EC4;&#x3002;<ul>
<li>&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;</li>
<li>&#x4E0D;&#x4FEE;&#x6539;&#x539F;&#x6570;&#x7EC4;</li>
<li>&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x8C03;&#x7528;&#x8FD4;&#x56DE;&#x7684;&#x8FD8;&#x662F;&#x7A00;&#x758F;&#x6570;&#x7EC4;<ul>
<li>&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;arr.map(Math.sqrt);<ul>
<li>map&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#x51FD;&#x6570;,</li>
<li>&#x76F4;&#x63A5;&#x4F20;&#x5165;&#x4E86;&#x4E00;&#x4E2A;Math.sqrt&#x65B9;&#x6CD5;,sqrt&#x65B9;&#x6CD5;&#x662F;&#x4E3A;&#x67D0;&#x4E2A;&#x6570;&#x5B57;&#x5F00;&#x5E73;&#x65B9;&#x7684;</li>
<li>&#x8C03;&#x7528;map&#x65B9;&#x6CD5;&#x4F20;&#x5165;Math.sqrt&#x7684;&#x65F6;&#x5019;,&#x53BB;&#x6389;&#x4E86;&#x62EC;&#x53F7;,&#x4E5F;&#x6CA1;&#x6709;&#x4F20;&#x5165;&#x53C2;&#x6570;</li>
<li>map&#x65B9;&#x6CD5;&#x5185;&#x90E8;&#x5E2E;&#x6211;&#x4EEC;&#x904D;&#x5386;&#x5E76;&#x4E14;&#x4F20;&#x5165;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>filter() &#x65B9;&#x6CD5;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x8C03;&#x7528;&#x7684;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x96C6;&#xFF0C;&#x4F20;&#x9012;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x7528;&#x6765;&#x903B;&#x8F91;&#x5224;&#x65AD;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x5E03;&#x5C14;&#x503C;&#xFF1B;<ul>
<li>&#x538B;&#x7F29;&#x7A7A;&#x7F3A;&#x6216;&#x5E76;&#x5220;&#x9664; undefined &#x548C; null &#x5143;&#x7D20;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; filter();</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">a = a.filter(<span class="function"><span class="keyword">function</span>(<span class="params">x</span>)</span>{</div><div class="line">  <span class="keyword">return</span> x !== <span class="literal">undefined</span> &amp;&amp; x !== <span class="literal">null</span>;</div><div class="line">});</div></pre></td></tr></table></figure>
<h2 id="&#x68C0;&#x6D4B;&#x6570;&#x7EC4;"><a href="#&#x68C0;&#x6D4B;&#x6570;&#x7EC4;" class="headerlink" title="&#x68C0;&#x6D4B;&#x6570;&#x7EC4;"></a>&#x68C0;&#x6D4B;&#x6570;&#x7EC4;</h2><ul>
<li>instanceof </li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[] <span class="keyword">instanceof</span> <span class="built_in">Array</span>; <span class="comment">// true</span></div><div class="line">{} <span class="keyword">instanceof</span> <span class="built_in">Array</span>; <span class="comment">// false</span></div></pre></td></tr></table></figure>
<p>&#x4F46;&#x662F;&#x5728;web&#x6D4F;&#x89C8;&#x5668;&#x591A;&#x7A97;&#x53E3;&#x6216;&#x7A97;&#x4F53;&#x5B58;&#x5728;&#x65F6;&#xFF0C;&#x6BCF;&#x4E2A;&#x5168;&#x5C40;&#x5BF9;&#x8C61;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x4E00;&#x7EC4;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;<br>&#x4E00;&#x4E2A;&#x7A97;&#x4F53;&#x4E2D;&#x7684;&#x5BF9;&#x8C61;&#x4E0D;&#x53EF;&#x80FD;&#x662F;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x7A97;&#x4F53;&#x4E2D;&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;&#x5B9E;&#x4F8B;&#x3002;<br>&#x56E0;&#x6B64;&#xFF0C;instanceof &#x64CD;&#x4F5C;&#x7B26;&#x4E0D;&#x80FD;&#x89C6;&#x4E3A;&#x4E00;&#x4E2A;&#x53EF;&#x9760;&#x7684;&#x6570;&#x7EC4;&#x68C0;&#x6D4B;&#x65B9;&#x6CD5;&#x3002;</p>
<ul>
<li>isArray(); ECMAScript 5 &#x4E2D;&#x7ED9;&#x51FA;&#x7684;&#x68C0;&#x6D4B;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x7684;&#x65B9;&#x6CD5;&#xFF1B;<ul>
<li>&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x662F;&#x5224;&#x65AD;&#x53D8;&#x91CF;&#x662F;&#x4E0D;&#x662F;&#x6570;&#x7EC4;</li>
</ul>
</li>
</ul>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5C01;&#x88C5;&#x68C0;&#x6D4B;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> isArray = <span class="built_in">Function</span>.isArray || <span class="function"><span class="keyword">function</span>(<span class="params">o</span>) </span>{</div><div class="line">  <span class="keyword">return</span> <span class="keyword">typeof</span> o === <span class="string">&quot;object&quot;</span> &amp;&amp; <span class="built_in">Object</span>.prototype.toString.call(o) === <span class="string">&quot;[object Array]&quot;</span>;</div><div class="line">}</div></pre></td></tr></table></figure>
<ul>
<li>forEach &#x65B9;&#x6CD5;&#xFF0C;&#x4ECE;&#x5934;&#x81F3;&#x5C3E;&#x904D;&#x5386;&#x6570;&#x7EC4;&#xFF0C;&#x4E3A;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x8C03;&#x7528;&#x6307;&#x5B9A;&#x7684;&#x51FD;&#x6570;&#xFF1B;<ul>
<li>&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x6570;&#x503C;&#x5143;&#x7D20;&#x3001;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x3001;&#x6570;&#x7EC4;&#x672C;&#x8EAB;</li>
<li>&#x65E0;&#x6CD5;&#x518D;&#x6240;&#x6709;&#x5143;&#x7D20;&#x4F20;&#x9012;&#x5B8C;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x4E4B;&#x524D;&#x7EC8;&#x6B62;&#x904D;&#x5386;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> data = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</div><div class="line"><span class="comment">// &#x8BA1;&#x7B97;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x548C;&#x503C;</span></div><div class="line"><span class="keyword">var</span> sum = <span class="number">0</span>;</div><div class="line">data.forEach(<span class="function"><span class="keyword">function</span>(<span class="params">v</span>)</span>{</div><div class="line">  sum += v;</div><div class="line">});</div><div class="line"><span class="built_in">console</span>.log(sum);  <span class="comment">// sum =&gt; 15</span></div><div class="line">data.forEach(funciton (v,i,a) {</div><div class="line">  a[i] = v + <span class="number">1</span>;</div><div class="line">});</div><div class="line"><span class="built_in">console</span>.log(data); <span class="comment">// [2,3,4,5,6];</span></div></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x7EC8;&#x6B62; forEach &#x5FAA;&#x73AF;</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">foreach</span> (<span class="params">a, f, t</span>)</span>{</div><div class="line">  <span class="keyword">try</span> { a.forEach (f, t)}</div><div class="line">  <span class="keyword">catch</span> (e) {</div><div class="line">    <span class="keyword">if</span> (e === foreach.break) <span class="keyword">return</span>;</div><div class="line">    <span class="keyword">else</span> <span class="keyword">throw</span> e;</div><div class="line">  }</div><div class="line">}</div><div class="line">foreach.break = <span class="keyword">new</span> <span class="built_in">Error</span>(<span class="string">&quot;StopIteration&quot;</span>);</div></pre></td></tr></table></figure>
<ul>
<li>reduce()&#x548C; reduceRight()<ul>
<li>reduce() &#x548C; reduceRight() &#x65B9;&#x6CD5;&#x4F7F;&#x7528;&#x6307;&#x5B9A;&#x7684;&#x51FD;&#x6570;&#x5C06;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x7EC4;&#x5408;&#xFF0C;&#x751F;&#x6210;&#x5355;&#x4E2A;&#x503C;&#x3002;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</div><div class="line"><span class="keyword">var</span> sum = a.reduce(<span class="function"><span class="keyword">function</span>(<span class="params">x, y</span>)</span>{</div><div class="line">  <span class="keyword">return</span> x + y;</div><div class="line">}); <span class="comment">// &#x6C42;&#x548C;</span></div><div class="line"></div><div class="line"><span class="keyword">var</span> max = a.reduce(<span class="function"><span class="keyword">function</span>(<span class="params">x, y</span>)</span>{</div><div class="line">  <span class="keyword">return</span> (x&gt;y)?x:y;</div><div class="line">});  <span class="comment">// &#x6C42;&#x6700;&#x5927;&#x503C;</span></div></pre></td></tr></table></figure>
<ul>
<li>reduce() &#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;<ul>
<li>&#x7B2C;&#x4E00;&#x4E2A;&#x662F;&#x6267;&#x884C;&#x7B80;&#x5316;&#x64CD;&#x4F5C;&#x7684;&#x51FD;&#x6570;&#x3002;&#x5316;&#x7B80;&#x51FD;&#x6570;&#x7684;&#x4EFB;&#x52A1;&#x5C31;&#x662F;&#x7528;&#x67D0;&#x79CD;&#x65B9;&#x6CD5;&#x628A;&#x4E24;&#x4E2A;&#x503C;&#x7EC4;&#x5408;&#x548C;&#x5316;&#x7B80;&#x4E3A;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7B80;&#x5316;&#x540E;&#x7684;&#x503C;&#x3002;</li>
<li>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x53EF;&#x9009;&#x53C2;&#x6570;</li>
</ul>
</li>
<li>reduceRight() &#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#x548C; reduce() &#x4E00;&#x6837;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x662F;&#x5B83;&#x6309;&#x7167;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#x4ECE;&#x9AD8;&#x5230;&#x4F4E;&#x5904;&#x7406;&#x6570;&#x7EC4;&#xFF1B;</li>
</ul>
<p>reduce() &#x548C; reduceRight() &#x90FD;&#x80FD;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x5B83;&#x6307;&#x5B9A;&#x4E86;&#x5316;&#x7B80;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65F6;&#x7684; this &#x5173;&#x952E;&#x503C;&#x3002;</p>
<p>&#x8BA1;&#x7B97;&#x4E24;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5E76;&#x96C6;&#xFF0C;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * [union description] &#x5982;&#x679C;&#x6709;&#x91CD;&#x540D;&#x5C5E;&#x6027;&#xFF0C;&#x4F7F;&#x7528; p &#x4E2D;&#x7684;&#x5C5E;&#x6027;</div><div class="line"> * @param  {[type]} o [description]</div><div class="line"> * @param  {[type]} p [description]</div><div class="line"> * @return {[type]}   [description] &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x5BF9;&#x8C61;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x540C;&#x65F6;&#x62E5;&#x6709; o &#x7684;&#x5C5E;&#x6027;</div><div class="line"> */</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">union</span> (<span class="params">o, p</span>) </span>{</div><div class="line">  <span class="keyword">return</span> extend (extend({}, o), p);</div><div class="line">}</div><div class="line"><span class="keyword">var</span> objs = [{<span class="attr">x</span>:<span class="number">1</span>}, {<span class="attr">y</span>:<span class="number">2</span>}, {<span class="attr">z</span>:<span class="number">3</span>}];</div><div class="line"><span class="keyword">var</span> merged = objs.reduce(union);  <span class="comment">// {x:1, y:2, z:3}</span></div></pre></td></tr></table></figure>
<p>&#x62E5;&#x6709;&#x540C;&#x540D;&#x5C5E;&#x6027;&#x65F6;&#xFF0C;reduce() &#x548C; reduceRight() &#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;&#x4E0D;&#x540C;&#xFF1B;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> objs = [{<span class="attr">x</span>:<span class="number">1</span>, <span class="attr">a</span>:<span class="number">1</span>}, {<span class="attr">y</span>:<span class="number">2</span>, <span class="attr">a</span>:<span class="number">2</span>}, {<span class="attr">z</span>:<span class="number">3</span>, <span class="attr">a</span>:<span class="number">3</span>}];</div><div class="line"><span class="keyword">var</span> lUnion = objs.reduce(union);  <span class="comment">// {x:1, y:2, z:3, a:1}</span></div><div class="line"><span class="keyword">var</span> lUnion = objs.reduceRight(union);  <span class="comment">// {x:1, y:2, z:3, a:3}</span></div></pre></td></tr></table></figure>
<h2 id="ECMAScript-6-&#x4E2D;&#x6570;&#x7EC4;&#x65B0;&#x65B9;&#x6CD5;"><a href="#ECMAScript-6-&#x4E2D;&#x6570;&#x7EC4;&#x65B0;&#x65B9;&#x6CD5;" class="headerlink" title="ECMAScript 6 &#x4E2D;&#x6570;&#x7EC4;&#x65B0;&#x65B9;&#x6CD5;"></a>ECMAScript 6 &#x4E2D;&#x6570;&#x7EC4;&#x65B0;&#x65B9;&#x6CD5;</h2><ul>
<li>Array.prototype.find &#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x627E;&#x51FA;&#x7B2C;&#x4E00;&#x4E2A;&#x7B26;&#x5408;&#x6761;&#x4EF6;&#x7684;&#x6570;&#x7EC4;&#x6210;&#x5458;&#x3002;<ul>
<li>&#x53C2;&#x6570;&#x662F;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x627E;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x8FD4;&#x56DE; true &#x7684;&#x6570;&#x7EC4;&#x9879;&#xFF0C;&#x7136;&#x540E;&#x8FD4;&#x56DE;&#x8BE5;&#x6570;&#x7EC4;&#x9879;&#xFF1B;</li>
<li>&#x627E;&#x4E0D;&#x5230;&#x8FD4;&#x56DE;undefined&#xFF1B;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> arr = [<span class="number">123</span>,<span class="number">23</span>];</div><div class="line">arr.find(functiton(num){</div><div class="line">  <span class="keyword">return</span> num === <span class="number">123</span>;</div><div class="line">});</div></pre></td></tr></table></figure>
<ul>
<li>&#x4E24;&#x4E2A;&#x9759;&#x6001;&#x65B9;&#x6CD5;<ul>
<li>Array.from<ul>
<li>&#x5C06;&#x4E00;&#x4E2A;&#x4F2A;&#x6570;&#x7EC4;&#x8F6C;&#x6210;&#x6B63;&#x771F;&#x7684;&#x6570;&#x7EC4;</li>
</ul>
</li>
<li>Array.of <ul>
<li>&#x5C06;&#x65B9;&#x6CD5;&#x4E2D;&#x53C2;&#x6570;&#x90FD;&#x6DFB;&#x52A0;&#x5230;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;</li>
</ul>
</li>
</ul>
</li>
<li>&#x64CD;&#x4F5C;&#x3001;&#x586B;&#x5145;&#x548C;&#x8FC7;&#x6EE4;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;<ul>
<li>Array.prototype.copyWidthin</li>
<li>Array.prototype.fill</li>
<li>Array.prototype.find<ul>
<li>&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF0C;&#x6BCF;&#x4E00;&#x9879;&#x6267;&#x884C;&#x8C03;&#x7528;&#x5B83;</li>
</ul>
</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> users = [</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;bb&apos;</span>, <span class="attr">age</span>:<span class="number">24</span>},</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;cc&apos;</span>, <span class="attr">age</span>:<span class="number">32</span>},</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;dd&apos;</span>, <span class="attr">age</span>:<span class="number">12</span>},</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;aa&apos;</span>, <span class="attr">age</span>:<span class="number">16</span>},</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;ed&apos;</span>, <span class="attr">age</span>:<span class="number">18</span>},</div><div class="line">  {<span class="attr">name</span>: <span class="string">&apos;aa&apos;</span>, <span class="attr">age</span>:<span class="number">29</span>}</div><div class="line">];</div><div class="line"><span class="built_in">console</span>.log(users.find(<span class="function"><span class="params">u</span> =&gt;</span> u.name === <span class="string">&apos;aa&apos;</span>)); <span class="comment">// {name: &apos;aa&apos;, age:16}</span></div></pre></td></tr></table></figure>
<ul>
<li>Array.prototype.findIndex<ul>
<li>&#x6709;&#x5173;&#x6570;&#x7EC4;&#x8FED;&#x4EE3;&#x7684;&#x65B9;&#x6CD5;</li>
</ul>
</li>
<li>Array.prototype.keys</li>
<li>Array.prototype.values</li>
<li>Array.prototype.entries</li>
<li>Array.prototype[Symbol.iterator]</li>
</ul>
<h2 id="&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;-&#x4F2A;&#x6570;&#x7EC4;"><a href="#&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;-&#x4F2A;&#x6570;&#x7EC4;" class="headerlink" title="&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;(&#x4F2A;&#x6570;&#x7EC4;)"></a>&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;(&#x4F2A;&#x6570;&#x7EC4;)</h2><p>JavaScript &#x7684;&#x7C7B;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#xFF1A;&#x628A;&#x62E5;&#x6709;&#x6570;&#x7EC4; length &#x5C5E;&#x6027;&#x548C;&#x5BF9;&#x5E94;&#x975E;&#x8D1F;&#x6574;&#x6570;&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x8C61;&#x770B;&#x7740;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x7EC4;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = {};</div><div class="line"><span class="keyword">var</span> i = <span class="number">0</span>;</div><div class="line"><span class="keyword">while</span> (i &lt; <span class="number">10</span>) {</div><div class="line">  a[i] = i * i;</div><div class="line">  i++;</div><div class="line">}</div><div class="line">a.length = i;</div><div class="line"><span class="comment">// &#x90A3;&#x4E48;&#x53EF;&#x4EE5;&#x5F53;&#x6210;&#x771F;&#x6B63;&#x7684;&#x6570;&#x7EC4;&#x904D;&#x5386;</span></div><div class="line"><span class="keyword">var</span> total = <span class="number">0</span>;</div><div class="line"><span class="keyword">for</span> (<span class="keyword">var</span> j = <span class="number">0</span>; j &lt; a.length; j++){</div><div class="line">  total += a[j];</div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x5224;&#x65AD;&#x662F;&#x5426;&#x662F;&#x4F2A;&#x6570;&#x7EC4;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">isArrayLike</span>(<span class="params">o</span>) </span>{</div><div class="line">  <span class="keyword">if</span> (o &amp;&amp; <span class="keyword">typeof</span> o === <span class="string">&quot;object&quot;</span> </div><div class="line">  &amp;&amp; <span class="built_in">isFinite</span>(o.length)</div><div class="line">  &amp;&amp; o.length &gt;=<span class="number">0</span> </div><div class="line">  &amp;&amp; o.length === <span class="built_in">Math</span>.floor(o.length)</div><div class="line">  &amp;&amp; o.length &lt; <span class="number">4294967296</span>)</div><div class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line">  <span class="keyword">else</span> </div><div class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="&#x4F5C;&#x4E3A;&#x6570;&#x7EC4;&#x7684;&#x5B57;&#x7B26;&#x4E32;"><a href="#&#x4F5C;&#x4E3A;&#x6570;&#x7EC4;&#x7684;&#x5B57;&#x7B26;&#x4E32;" class="headerlink" title="&#x4F5C;&#x4E3A;&#x6570;&#x7EC4;&#x7684;&#x5B57;&#x7B26;&#x4E32;"></a>&#x4F5C;&#x4E3A;&#x6570;&#x7EC4;&#x7684;&#x5B57;&#x7B26;&#x4E32;</h2><p>ECMAScript 5 &#x4E2D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x9664;&#x4E86;&#x7528; charAt() &#x8BBF;&#x95EE;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x65B9;&#x62EC;&#x53F7;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> str = <span class="string">&quot;string&quot;</span>;</div><div class="line"><span class="built_in">console</span>.log(str.charAt(<span class="number">1</span>));  <span class="comment">// =&gt; &quot;t&quot;;</span></div><div class="line"><span class="built_in">console</span>.log(s[<span class="number">1</span>]);  <span class="comment">// =&gt; &quot;t&quot;;</span></div></pre></td></tr></table></figure>
<p><strong>&#x672C;&#x6587;&#x53C2;&#x8003;&#x81EA;&#xFF1A;&#x300A;JavaScript &#x6743;&#x5A01;&#x6307;&#x5357;&#x300B;</strong></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>坚持原创技术分享，您的支持将是我最大的鼓励！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag">#js</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/05/02/js-的对象/" rel="next" title="js 的对象">
                <i class="fa fa-chevron-left"></i> js 的对象
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2014/05/15/js-String对象/" rel="prev" title="js String对象">
                js String对象 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2014/05/11/js-的数组/"
     data-title="js 的数组"
     data-content=""
     data-url="https://hongqinma.github.io/2014/05/11/js-的数组/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2014/05/11/js-的数组/"
           data-title="js 的数组" data-url="https://hongqinma.github.io/2014/05/11/js-的数组/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">20</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#js-的内置对象-数组Array"><span class="nav-number">1.</span> <span class="nav-text">js 的内置对象: 数组Array</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组声明"><span class="nav-number">2.</span> <span class="nav-text">数组声明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组元素的读和写"><span class="nav-number">3.</span> <span class="nav-text">数组元素的读和写</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#数组的合法表达式"><span class="nav-number">3.1.</span> <span class="nav-text">数组的合法表达式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数组索引和对象属性"><span class="nav-number">3.2.</span> <span class="nav-text">数组索引和对象属性</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组的长度"><span class="nav-number">4.</span> <span class="nav-text">数组的长度</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#稀疏数组"><span class="nav-number">5.</span> <span class="nav-text">稀疏数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组冒泡排序"><span class="nav-number">6.</span> <span class="nav-text">数组冒泡排序</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组的方法"><span class="nav-number">7.</span> <span class="nav-text">数组的方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ECMAScript-5-中的数组方法"><span class="nav-number">8.</span> <span class="nav-text">ECMAScript 5 中的数组方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#检测数组"><span class="nav-number">9.</span> <span class="nav-text">检测数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#ECMAScript-6-中数组新方法"><span class="nav-number">10.</span> <span class="nav-text">ECMAScript 6 中数组新方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#类数组对象-伪数组"><span class="nav-number">11.</span> <span class="nav-text">类数组对象(伪数组)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#作为数组的字符串"><span class="nav-number">12.</span> <span class="nav-text">作为数组的字符串</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
